package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86138
 * Date: 2024-06-04
 * Time: 21:44
 */
public class Test {
    public static void func(Animal animal){
        animal.eat();
    }

    public static void main1(String[] args) {
        Dog dog = new Dog("旺财",1);
        func(dog);

        Bird bird = new Bird("小鸟",2);
        func(bird);




    }

    public static void main(String[] args) {
        Animal dog = new Dog("旺财",1);//父类引用 引用了子类的对象 ---- 向上转型
        dog.eat();//只能引用父类的方法
        //dog.bark()//err不能引用子类中的方法

        //向下转型
        Dog dog1 = (Dog)dog;
        dog1.bark();
    }
}
